import React, { Component } from 'react'
import axios from 'axios'
import { withRouter} from 'react-router-dom'
import { connect } from 'react-redux'
import {loadData} from '../../redux/user.redux'
@withRouter
@connect(
  null,
  {loadData}
)
class AuthRoute extends Component{
  constructor(props){
    super(props)
  }
  componentDidMount(){
    const publicList = ['/login','/register']
    const pathname = this.props.location.pathname
    if(publicList.indexOf(pathname)>-1) {
      return null
    }
    axios.get('/user/info').
      then(res=>{
        if(res.status===200){
          if(res.data.code ===0){
            this.props.loadData(res.data.data)
            //有登录信息
          }else{
            this.props.history.push('/login')
          }
        }
      })
    //用户信息
    //是否登录
    //用户身份
    //是否完善信息
  }
  render(){
    return null
  }
}

export default AuthRoute